#include <vector>
#include <iostream>
#include <iomanip>

using namespace std;

vector<vector<int>> yangHuiTriangle(int level) {
  vector<vector<int>> result {{1}};

  for (int l = 1; l < level; ++l) {
    vector<int> tmp(l + 1, 0);

    for (int j = 0; j < l + 1; ++j) {
      if (j == 0 || j == l) {
        tmp[j] = 1;
      }
      else {
        tmp[j] = result[l - 1][j - 1] + result[l - 1][j];
      }
    }

    result.push_back(tmp);
  }

  return result;
}

void printYangHuiTriangle(int level) {
  auto result = yangHuiTriangle(level);
  int spaces = result.back().size();

  for (auto v : result) {
    cout << setw(spaces * 2 - 1);
    --spaces;
    for (int n : v) {
      // Only odd number of spaces can form a triangle perfectly.
      // The leading spaces is equal to spaces * 2 - 1.
      cout << n << "   ";
    }
    cout << endl;
  }
}

int main(int argc, char const *argv[])
{
  /* code */
  printYangHuiTriangle(3);
  return 0;
}
